﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ScreenCapture
{

    /// <summary>
    /// Interaction logic for CVRecordMaskWindow.xaml
    /// </summary>
    public partial class MaskWindow : Window
    {
        ///// <summary>
        ///// 确认选择
        ///// </summary>
        //public event Action<bool> ConfirmEvent;
        /// <summary>
        /// 暂停选择，是否确认
        /// </summary>
        public event Action ConfirmCheckingEvent;
        /// <summary>
        /// 继续选择
        /// </summary>
        public event Action ContinueSelectEvent;
        public MaskWindow()
        {
            InitializeComponent();
        }

        public bool ShowBackMask
        {
            get { return (bool)GetValue(ShowBackMaskProperty); }
            set { SetValue(ShowBackMaskProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ShowBackMask.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ShowBackMaskProperty =
            DependencyProperty.Register("ShowBackMask", typeof(bool), typeof(MaskWindow), new PropertyMetadata(false));


        private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.ConfirmCheckingEvent?.Invoke();
            //this.ConfirmEvent?.Invoke(true);
            confirmPanel.Visibility = Visibility.Visible;
        }

        private void Esc_Click(object sender, ExecutedRoutedEventArgs e)
        {
            //this.ConfirmEvent?.Invoke(false);
            this.DialogResult = false;
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.ContinueSelectEvent?.Invoke();
            confirmPanel.Visibility = Visibility.Collapsed;
        }

        private void Confirm_Click(object sender, RoutedEventArgs e)
        {
            //this.ConfirmEvent?.Invoke(true);
            loadingImage.Visibility = Visibility.Visible;
            this.DialogResult = true;
        }

        /// <summary>
        /// 为了能直接拿到结果
        /// </summary>
        /// <returns></returns>
        public new bool ShowDialog()
        {
            var result = base.ShowDialog();
            return result.Value;
        }

    }
}
